package com.polaris.live.utils.image

import android.graphics.Bitmap
import android.graphics.BitmapFactory

/**
 * BitmapUtils
 *
 * @author Created by lucas on 2023/10/23 09:35
 */
object BitmapUtils {

    const val MAX_WIDTH = 720
    const val MAX_HEIGHT = 720

    /**
     * 获得BitmapFactory，不加载到内存
     *
     * @return 图片配置
     */
    fun getBitmapOption(): BitmapFactory.Options {
        val options = BitmapFactory.Options()
        options.inJustDecodeBounds = true
        options.inPreferredConfig = Bitmap.Config.ARGB_8888
        return options
    }

    /**
     * 获取Bitmap的宽高
     *
     * @param path 图片地址
     */
    fun readBitmapSize(path: String): Pair<Int, Int>? {
        return readBitmapSize(path, getBitmapOption())
    }

    /**
     * 获取Bitmap的宽高
     *
     * @param path    图片地址
     * @param options 配置参数
     */
    fun readBitmapSize(path: String, options: BitmapFactory.Options): Pair<Int, Int>? {
        if (path.isEmpty()) {
            return null
        }
        BitmapFactory.decodeFile(path, options)
        return options.outWidth to options.outHeight
    }
}